package it.unical.canonaco.rende.igpe.game.cbv.guilayer.components;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;

import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JScrollBar;
import javax.swing.plaf.basic.BasicScrollBarUI;
import javax.swing.plaf.metal.MetalScrollBarUI;


public class ThinScrollBar extends JScrollBar {
	
	private static final int DEFAULT_WIDTH = 15;
	private static final int DEFAULT_HEIGHT = 15;
	private static int ROUNDNESS = 10;
	private static int START_THUMB = 2;
	private static int END_THUMB = -4;
	
       public ThinScrollBar(int orientation) {
    	   this.setOrientation(orientation);
    	   this.setPreferredSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT));
    	   this.setUI(new DarkScrollBarUI());
	}

       
private class DarkScrollBarUI extends BasicScrollBarUI {
	
	// delete arrows by returning 0-sized button
	private JButton button = new JButton() {

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(0, 0);
        }

    };
    public DarkScrollBarUI() {
    	super();
    }
    
    @Override
    protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {   
    	
    	Graphics2D g2d = (Graphics2D) g;
    	g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    	g2d.setColor(Color.gray.darker());
    	
//    	if(getOrientation() == VERTICAL)
    		g2d.fillRoundRect(thumbBounds.x+START_THUMB, thumbBounds.y+START_THUMB, thumbBounds.width+END_THUMB,
    				thumbBounds.height+END_THUMB, ROUNDNESS, ROUNDNESS);
    }

    @Override
    protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {        
    	
    	Graphics2D g2d = (Graphics2D) g;
    	g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    	g2d.setColor(Color.LIGHT_GRAY);
    	g2d.fillRect(trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height);
    }
    
    @Override
    protected JButton createDecreaseButton(int orientation) {
        return button;
    }

    @Override
    protected JButton createIncreaseButton(int orientation) {
        return button;
    }
    
  }

}